<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>API: widget   keycmd.js  (YUI Library)</title>

	<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css?stamp=1316139452.2" />
	<link rel="stylesheet" type="text/css" href="assets/api.css?stamp=1316139452.2" />

    <script type="text/javascript" src="assets/api-js?stamp=1316139452.2"></script>
    <script type="text/javascript" src="assets/ac-js?stamp=1316139452.2"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">
	<div id="hd">
        <h1><a href="http://developer.yahoo.com/yui/" title="g-javascript-lib">g-javascript-lib</a></h1>
        <h3>widget&nbsp; <span class="subtitle">1.0.0</span></h3>
        <a href="./index.html" title="g-javascript-lib">g-javascript-lib</a> 
            &gt; <a href="./module_widget.html" title="widget">widget</a>
                
                 &gt; keycmd.js (source view) 
        <form onsubmit="return false">
            <div id="propertysearch">
                Search: <input autocomplete="off" id="searchinput" />
                <div id="searchresults">
                    &nbsp;
                </div>
            </div>
        </form>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
                <fieldset>
                    <legend>Filters</legend>
                <span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
                <span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
                <span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
                </fieldset>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 .classopts { display:none; }
                        </style>
<div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
	<span class="nx">KeyCommander</span> <span class="o">=</span> <span class="nx">G</span><span class="p">.</span><span class="nx">GClass</span><span class="p">(</span><span class="s1">&#39;Widget&#39;</span><span class="p">,</span> <span class="s1">&#39;KeyCommander&#39;</span><span class="p">);</span>

	<span class="nx">KeyCommander</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__init</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">cmdlist</span><span class="p">)</span> <span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_buf</span> <span class="o">=</span> <span class="p">[];</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_cmdList</span> <span class="o">=</span> <span class="nx">cmdlist</span> <span class="o">||</span> <span class="p">{};</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_enabled</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span> <span class="o">=</span> <span class="p">[];</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_timeout</span> <span class="o">=</span> <span class="mi">1000</span><span class="p">;</span>
	<span class="p">}</span>

	<span class="nx">KeyCommander</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">enable</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span>
	<span class="p">{</span>
		<span class="nx">G</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">bind</span><span class="p">(</span><span class="s1">&#39;onkeypress&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">on_key</span><span class="p">,</span> <span class="k">this</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_cmdList</span><span class="p">;</span>
	<span class="p">}</span>

	<span class="nx">KeyCommander</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">disable</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span>
	<span class="p">{</span>
		<span class="nx">G</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">unbind</span><span class="p">(</span><span class="s1">&#39;onkeypress&#39;</span><span class="p">,</span> <span class="nx">on_key</span><span class="p">,</span> <span class="k">this</span><span class="p">);</span>
	<span class="p">}</span>

	<span class="nx">KeyCommander</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">load_cmd_list</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">cmdlist</span><span class="p">)</span> 
	<span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_cmdList</span> <span class="o">=</span> <span class="nx">cmdlist</span><span class="p">;</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_cmdList</span><span class="p">;</span>
	<span class="p">}</span>


	<span class="nx">KeyCommander</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">on_key</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">evt</span><span class="p">)</span> 
	<span class="p">{</span>
		<span class="kd">var</span> <span class="nx">k</span> <span class="o">=</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">evt</span><span class="p">.</span><span class="nx">which</span> <span class="o">||</span> <span class="nx">evt</span><span class="p">.</span><span class="nx">keyCode</span><span class="p">);</span>

		<span class="k">if</span> <span class="p">(</span><span class="nx">k</span> <span class="k">in</span> <span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">cmd</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span><span class="p">[</span><span class="nx">k</span><span class="p">];</span>
			<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span><span class="p">(</span><span class="nx">cmd</span><span class="p">.</span><span class="nx">func</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;function&#39;</span><span class="p">)</span> <span class="p">{</span>
				<span class="nx">cmd</span><span class="p">.</span><span class="nx">func</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">cmd</span><span class="p">.</span><span class="nx">obj</span><span class="p">);</span>
				<span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_cmdList</span><span class="p">;</span>
			<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
				<span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span> <span class="o">=</span> <span class="nx">cmd</span><span class="p">;</span>		<span class="c1">// Wait further key</span>
			<span class="p">}</span>
		<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>	
			<span class="c1">// Error cmd, go back to begining.</span>
			<span class="c1">// Todo: make a beep on a unexpected key</span>
			<span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_cmdList</span><span class="p">;</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;unsupported command.&#39;</span><span class="p">);</span>
		<span class="p">}</span>

		<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_timer</span> <span class="o">==</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>
			<span class="kd">var</span> <span class="nx">_self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
			<span class="k">this</span><span class="p">.</span><span class="nx">_timer</span> <span class="o">=</span> <span class="nx">setTimeout</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
				<span class="nx">_self</span><span class="p">.</span><span class="nx">on_timeout</span><span class="p">();</span>
			<span class="p">},</span> <span class="k">this</span><span class="p">.</span><span class="nx">_timeout</span><span class="p">);</span>
		<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
			<span class="nx">clearTimeout</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_timer</span><span class="p">);</span>
		<span class="p">}</span>

	<span class="p">}</span>

	<span class="nx">KeyCommander</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">on_timeout</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span>
	<span class="p">{</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">_filtered</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_cmdList</span><span class="p">;</span>
	<span class="p">}</span>
 <span class="p">})();</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div id="moduleList" class="module">
                        <h4>Modules</h4>
                        <ul class="content">
                                <li class=""><a href="module_base.html" title="base">base</a></li>
                                <li class=""><a href="module_svg.html" title="svg">svg</a></li>
                                <li class=""><a href="module_test.html" title="test">test</a></li>
                                <li class=""><a href="module_utils.html" title="utils">utils</a></li>
                                <li class="selected"><a href="module_widget.html" title="widget">widget</a></li>
                        </ul>
                    </div>

                    <div id="classList" class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="widget.DataGrid.html" title="widget.DataGrid">widget.DataGrid</a></li>
                                <li class=""><a href="Widget.TreeView.html" title="Widget.TreeView">Widget.TreeView</a></li>
                        </ul>
                    </div>

                    <div id="fileList" class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class="selected"><a href="keycmd.js.html" title="keycmd.js">keycmd.js</a></li>
                                <li class=""><a href="listmenu.js.html" title="listmenu.js">listmenu.js</a></li>
                                <li class=""><a href="scrollbar.js.html" title="scrollbar.js">scrollbar.js</a></li>
                                <li class=""><a href="toolbar.js.html" title="toolbar.js">toolbar.js</a></li>
                                <li class=""><a href="treeview.js.html" title="treeview.js">treeview.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2011 Yahoo! Inc. All rights reserved.
	</div>
</div>
<script type="text/javascript">
    ALL_YUI_PROPS = [{"url": "Widget.TreeView.html#method_add_node", "access": "", "host": "Widget.TreeView", "type": "method", "name": "add_node"}, {"url": "Widget.TreeView.html#method_clear", "access": "", "host": "Widget.TreeView", "type": "method", "name": "clear"}, {"url": "widget.DataGrid.html#method_clear_view", "access": "", "host": "widget.DataGrid", "type": "method", "name": "clear_view"}, {"url": "widget.DataGrid.html#method_current_page", "access": "", "host": "widget.DataGrid", "type": "method", "name": "current_page"}, {"url": "widget.DataGrid.html#method_first_page", "access": "", "host": "widget.DataGrid", "type": "method", "name": "first_page"}, {"url": "widget.DataGrid.html#method_go", "access": "", "host": "widget.DataGrid", "type": "method", "name": "go"}, {"url": "Widget.TreeView.html#method___init", "access": "", "host": "Widget.TreeView", "type": "method", "name": "__init"}, {"url": "widget.DataGrid.html#method_last_page", "access": "", "host": "widget.DataGrid", "type": "method", "name": "last_page"}, {"url": "widget.DataGrid.html#method_link_data", "access": "", "host": "widget.DataGrid", "type": "method", "name": "link_data"}, {"url": "Widget.TreeView.html#method_link_data", "access": "", "host": "Widget.TreeView", "type": "method", "name": "link_data"}, {"url": "widget.DataGrid.html#method_next_page", "access": "", "host": "widget.DataGrid", "type": "method", "name": "next_page"}, {"url": "widget.DataGrid.html#method_page_total", "access": "", "host": "widget.DataGrid", "type": "method", "name": "page_total"}, {"url": "widget.DataGrid.html#method_prev_page", "access": "", "host": "widget.DataGrid", "type": "method", "name": "prev_page"}, {"url": "Widget.TreeView.html#method_render", "access": "", "host": "Widget.TreeView", "type": "method", "name": "render"}, {"url": "widget.DataGrid.html#method_set_current", "access": "", "host": "widget.DataGrid", "type": "method", "name": "set_current"}, {"url": "Widget.TreeView.html#method_set_current", "access": "", "host": "Widget.TreeView", "type": "method", "name": "set_current"}, {"url": "widget.DataGrid.html#method_set_page_size", "access": "", "host": "widget.DataGrid", "type": "method", "name": "set_page_size"}, {"url": "Widget.TreeView.html#method_toggle_folder", "access": "", "host": "Widget.TreeView", "type": "method", "name": "toggle_folder"}];
</script>
</body>
</html>
